﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL;
using IFactory;

public partial class Admin_Department_DepartmentAdd : System.Web.UI.Page
{
    DepartmentInfoManager dllDepartment = new DepartmentInfoManager();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
        }
    }



    /// <summary>
    /// 部门添加并继续事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <author>grokyao</author>
    /// <date>2009-2-13</date>
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        string _departmentName = this.txtDepartmentName.Text.Trim();
        int isExist = dllDepartment.isExist(_departmentName);
        if (isExist == -1)
        {
            Utility.HttpHelp.alert("您要添加的部门已存在！", Page);
            return;
        }
        object[] _value = new object[3];
        //获得 部门编号 和 部门名称
        _value[0] = Convert.ToInt32(this.txtDepartmentNo.Text.Trim());
        _value[1] = this.txtDepartmentName.Text.Trim();
        _value[2] = Utility.HttpHelp.getParamsInt("DepartmentParentId");
        int result =dllDepartment.add(_value);
        if (result == 0)
        {
            Utility.Error.RedirectErrorPage("添加部门未成功，请重试！");
        }
        else
        {
            Page.RegisterStartupScript("refresh", "<script>window.opener.location.href=window.opener.location.href;</script>");
        }
        
    }

    /// <summary>
    /// 添加并退出事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <author>grokyao</author>
    /// <date>2009-2-13</date>
    protected void btnAddAndReturn_Click(object sender, EventArgs e)
    {
        string _departmentName = this.txtDepartmentName.Text.Trim();
        int isExist = dllDepartment.isExist(_departmentName);
        if (isExist == -1)
        {
            Utility.HttpHelp.alert("您要添加的部门已存在！", Page);
            return;
        }
        object[] _value = new object[3];
        _value[0] = Convert.ToInt32(this.txtDepartmentNo.Text.Trim());
        _value[1] = this.txtDepartmentName.Text.Trim();
        _value[2] = Utility.HttpHelp.getParamsInt("DepartmentParentId");
        int result = dllDepartment.add(_value);
        if (result == 0)
        {
            Utility.Error.RedirectErrorPage("添加部门未成功，请重试！");
        }        
        Utility.HttpHelp.closeWindow("Department_Manager.aspx",Page);
    }


    /// <summary>
    /// 取消事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <author>grokyao</author>
    /// <date>2009-2-13</date>
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Utility.HttpHelp.closeWindow("Department_Manager.aspx", Page);
    }
}
